package com.briup.cms.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.briup.cms.domain.Slideshow;
import com.briup.cms.service.ISlideshowService;
import com.briup.cms.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author briup
 * @since 2023-03-09
 */
@Api("轮播图模块")
@RestController
@RequestMapping("/slideshow")
public class SlideshowController {

    @Autowired
    ISlideshowService slideshowService;

    @ApiOperation("新增或修改轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "slideshow",value = "新增或修改的轮播图信息")
    })
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Slideshow slideshow){
        slideshowService.saveOrUpdate(slideshow);
        return Result.success();
    }

    @ApiOperation("删除轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "轮播图id")
    })
    @GetMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        slideshowService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("批量删除轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "轮播图id的集合")
    })
    @PostMapping("/deleteByIdAll")
    public Result deleteByIdAll(@RequestBody List<Long> ids){
        slideshowService.deleteByIds(ids);
        return Result.success();
    }

    @ApiOperation("条件查询轮播图信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小"),
            @ApiImplicitParam(name = "status",value = "状态")
    })
    @GetMapping("/query")
    public Result query(int pageNum,int pageSize,String status){
        IPage<Slideshow> result = slideshowService.query(pageNum, pageSize, status);
        return Result.success(result);
    }
}

